<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
              <a-input placeholder="请输入项目名称" v-model="projectName01"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目类型">
              <a-input placeholder="请输入项目类型" v-model="projectType01"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="专家人数">
                <a-input placeholder="请输入专家人数" v-model="queryParam.professorNumber"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="find01" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
<!--              <a @click="handleToggleSearch" style="margin-left: 8px">-->
<!--                {{ toggleSearchStatus ? '收起' : '展开' }}-->
<!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
<!--              </a>-->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="did" type="primary" icon="check-circle">已完成</a-button>
      <a-button @click="doing" type="primary" icon="pause-circle">抽取中</a-button>
      <a-button @click="undid" type="primary" icon="info-circle" >未抽取</a-button>
      <a-button @click="donot" type="primary" icon="exclamation-circle">抽取失败</a-button>
<!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
<!--        <a-menu slot="overlay">-->
<!--          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
<!--          &lt;!&ndash;<a-menu-item key="2" @click="professorRandomChoose"><a-icon type="user-add" />专家抽取</a-menu-item>&ndash;&gt;-->
<!--        </a-menu>-->
<!--        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
<!--      </a-dropdown>-->
    </div>
    <!-- table区域-begin -->

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :expandedRowKeys="childRows"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @expand="handleExpand"
        @change="handleTableChange">
      >
        <span slot="projectStatus" slot-scope="text,record">
          <a :class="record.project.projectStatus==='已完成' ? 'fontgreen' :(record.project.projectStatus==='抽取中' ? 'fontyellow' : 'fontred')">{{record.project.projectStatus}}</a>
        </span>
        <span slot="action" slot-scope="text, record">
            <a-button type="dashed"
                      :disabled="!(record.project.projectStatus==='待确认')"
                      :class="record.project.projectStatus==='待确认'?'fontred':'fontdelete'"
                      @click="sendProfessorChooseToDing(record.id)">{{record.project.projectStatus==='待确认'?'消息推送':'已推送'}}
            </a-button>
        </span>

        <!--内嵌表格-->
          <a-table
          rowKey="dingUserId"
          slot="expandedRowRender"
          :columns="innerColumns"
          :data-source="professorList"
          :pagination="false"
          slot-scope="record1"
          >
          <span slot="professorInProjectStates" slot-scope="text,record">
            <a :class="record.professorInProjectStates==='同意' ? 'fontgreen' : (record.professorInProjectStates==='待审核' ? 'fontyellow':(record.professorInProjectStates==='管理员删除')?'fontdelete':'fontred')">{{record.professorInProjectStates}}</a>
          </span>
          <span slot="action" slot-scope="text, record">
<!--            <a @click="deleteOneProfessor(record)">删除</a>-->
            <JInputPop
              :disabled="!((record1.project.projectStatus==='待确认')&&(record.professorInProjectStates==='等待管理员确认'))"
              title="删除原因"
              isbutton="true"
              :record="record"
              @change="deleteOneProfessor"
            />
          </span>

          </a-table>
      </a-table>

    <projectProfessorInfo-modal ref="modalForm" @ok="modalFormOk"></projectProfessorInfo-modal>
  </a-card>
</template>
<style>
  .fontgreen{
    color:green;
  }
  .fontyellow{
    color:gold;
  }
  .fontred{
    color:red;
  }
  .fontdelete{
    color: #aaa0a0;
  }
</style>

<script>

  import { deleteAction, getAction,downFile,getFileAccessHttpUrl } from '@/api/manage'
  import '@/assets/less/TableExpand.less'
  import { loadCategoryData } from '@/api/api'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ProjectProfessorInfoModal from './modules/ProjectProfessorInfoModal'
  import JInputPop from '@/components/jeecg/minipop/JInputPop'
  export default {
    name: "ProjectProfessorInfoList",
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      ProjectProfessorInfoModal,
      JInputPop,
    },
    data () {
      return {
        description: '项目所需专家抽取状态管理页面',
        professorList:[],
        childRows:[],
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'项目名称',
            align:"center",
            dataIndex: 'project.projectName'
          },
/*          {
            title:'项目类型',
            align:"center",
            dataIndex: 'project.projectType'
          },*/
          {
            title:'评标时间',
            align:"center",
            dataIndex:'project.professorWorkBeginTime'
          },

          {
            title:'评标地点',
            align:"center",
            dataIndex:'project.professorWorkAddress'
          },
          {
            title: '项目金额',
            align: "center",
            dataIndex: 'project.projectAmount'
          },
          {
            title:'项目状态',
            align:"center",
            scopedSlots: { customRender: 'projectStatus' },
            // dataIndex:'project.projectStatus'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            // fixed:"right",
            width:100,
            scopedSlots: { customRender: 'action' }
          }
        ],
         innerColumns:[
          { title: '专家姓名', dataIndex: 'professorName' },
          { title: '专家在项目中的职位', dataIndex:'professorInProjectProfessorType' },
          { title: '是否同意',
            // dataIndex: 'professorInProjectStates',
            scopedSlots: { customRender: 'professorInProjectStates' }
          },
           {
             title: '操作',
             dataIndex: 'action',
             align:"center",
             // fixed:"right",
             width:100,
             scopedSlots: { customRender: 'action' }
           }
        ],
        url: {
          list:"/org/projectOwnProfessor/list",
          list01:"/org/projectOwnProfessor/list01/",
          delete:"/org/projectOwnProfessor/deleteOneProfessor",
          sendToDing:"/sendProfessorChooseToDing"
        },
        dictOptions:{},
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      sendProfessorChooseToDing(projectid){
        console.log(projectid);
        var that = this;
        let sendUrl = that.url.sendToDing+"/"+projectid;
        that.loading=true;
        getAction(sendUrl,"").then((res)=>{
          that.$message.success(res.message)
          that.loadData();
          that.childRows=[];
        }).finally(()=>{
          that.loading=false;
        })
      },
      handleExpand(expanded,record) {
        if (expanded === true) {
          this.professorList = record.project.professorList;
          this.childRows=[];
          this.childRows.push(record.id);
          console.log(this.childRows)
        }else{
          this.childRows=[];
        }
      },
      initDictConfig(){
        loadCategoryData({code:'B03'}).then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'professorType', res.result)
          }
        })
      },
      professorRandomChoose: function (id) {
        if(!this.url.randomChoose){
          this.$message.error("请设置url.randomChoose属性!")
          return
        }
        // if (this.selectedRowKeys.length <= 0) {
        //   this.$message.warning('请选择一条记录！');
        //   return;
        // } else {
          var ids = "";
          // for (var a = 0; a < this.selectedRowKeys.length; a++) {
          //   ids += this.selectedRowKeys[a] + ",";
          // }
          ids=id;
          var that = this;
          this.$confirm({
            title: "确认信息无误开始抽取专家",
            content: "是否抽取专家?",
            onOk: function () {
              that.loading = true;
              deleteAction(that.url.randomChoose, {ids: ids}).then((res) => {
                if (res.success) {
                  that.$message.success(res.message);
                  that.loadData();
                  that.onClearSelected();
                } else {
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.loading = false;
              });
            }
          });
        },
      deleteOneProfessor:function (deleteCause,record) {
        var that = this;
        that.loading = true;
        var deleteUrl=this.url.delete+"/"+this.childRows[0]+"/"+record.dingUserId+"/"+deleteCause;
        getAction(deleteUrl,"").then((res)=>{
          console.log(res);
          that.$message.success(res.message);
          that.loadData();
          that.childRows=[];
        }).finally(() => {
          that.loading = false;
        });
      }
    },

  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>